var textadd = document.querySelector('.textadd');
var lis = document.querySelector('.lis');

// 添加
textadd.onkeyup = function(e){
	var text = textadd.value;
	if(e.keyCode == 13){
		if(this.value == 0){
			alert('请输入添加的内容');
		}else{
			var li = document.createElement("li");
			li.innerHTML=`
						<div class="tuimg">
							<img src="./imager/checkbox.dark.big.png" alt="" class="poto">
						</div>
						<span class="texezi">${text}</span>
						`
			lis.appendChild(li);
			textadd.value = '';
		}
	}
}
// 删除
var listB = document.querySelector('.listB');
var done = document.querySelector('.done');
lis.onclick = function(e){
	if(e.target.classList.contains('poto')){
		e.target.parentNode.parentNode.remove();
		var textB = e.target.parentNode.parentNode.innerText;
		var li = document.createElement("li");
		li.innerHTML = `<div class="tuimg">
							<img src="./imager/checkbox.light.big.png" alt="" class="poto">
						</div>
						<span class="xian">${textB}</span>
						`
		listB.appendChild(li);
		done.style.display = "block";
	}
}

// 返回
listB.onclick = function(e){
	if(e.target.classList.contains('poto')){
		e.target.parentNode.parentNode.remove();
		var textB = e.target.parentNode.parentNode.innerText;
		var li = document.createElement("li");
		li.innerHTML = `<div class="tuimg">
							<img src="./imager/checkbox.dark.big.png" alt="" class="poto">
						</div>
						<span class="texezi">${textB}</span>
						`
		lis.appendChild(li);
		done.style.display = "none";
	}
}

//删除按钮
var delebtn = document.querySelector('.delete');
delebtn.onclick = function(e){
	var delelist = document.querySelectorAll('.listB>li');
	if(delelist.length == 0){
		alert('没有删除的内容');
	}else{
		var queding = confirm('确定要清空所有内容吗？');
		if(queding){
			for(var i=0; i<delelist.length; i++){
				listB.removeChild(delelist[i]);
			}
		}
		done.style.display = "none";
	}
}